#include <iostream>
#include <string>

#include "medved/functor.hpp"
#include "medved/typelist.hpp"
#include "medved/scheduler.hpp"
#include "medved/manager.hpp"

using namespace Medved;

typedef Singleton<Scheduler> TheScheduler;

class A
{
public:
	void f(int a)
	{
		std::cout << "f(" << a << ") with ";
		std::cout << "this == 0x" << this << std::endl;
	}
};

typedef Scheduler::Action Action;

void T(int, const Action &a)
{
	a();
}

class D
{
public:
	void operator()(int, const Action &a) const
	{
		a();
	}
};

class M : public Managed {};

class Dummy {
public:
	void destroy(int id)
	{
		M *arg = static_cast<M *>(TheManager::instance().get(id));
		std::cout << "destroy(" << id << "), arg = 0x" << arg << '\n';
	}
};

int main()
{
	M *a = new M;
	Dummy dummy;

//	Functor<void, Seq<int> > fDestroy(destroy);

	TheScheduler::instance().schedule(1, bind(makeFunctor(dummy, &Dummy::destroy), a->getId()));
	std::cout << "registered: 0x" << a << '\n';
	M *b = new M(*a);
	delete a;
	TheScheduler::instance().timeStep();
	delete b;
}

